<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <div>
          <!-- <a-collapse v-model="activeKey"> -->
          <!-- <a-collapse-panel header="合同信息" key="1"> -->
          <a-row class="form-row" :gutter="24">
            <a-col :lg="8">
              <a-form-item label="合同编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-input v-decorator="['fxy01', validatorRules.fxy01]" placeholder="请输入合同编号"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="8">
              <a-form-item label="人员类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-input v-decorator="['fxy02', validatorRules.fxy02]" placeholder="请输入人员类型"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="8">
              <a-form-item label="姓名" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-input v-decorator="['fxy03', validatorRules.fxy03]" placeholder="请输入姓名"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="8">
              <a-form-item label="身份证号" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-input v-decorator="['fxy04', validatorRules.fxy04]" placeholder="请输入身份证号"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="8">
              <a-form-item label="电话" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-input v-decorator="['fxy05', validatorRules.fxy05]" placeholder="请输入电话"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="8">
              <a-form-item label="email" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-input v-decorator="['fxy06', validatorRules.fxy06]" placeholder="请输入email"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="8">
              <a-form-item label="fxy用户ID" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-input v-decorator="['fxy07', validatorRules.fxy07]" placeholder="请输入fxy用户ID"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="8">
              <a-form-item label="身份证正面" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-input v-decorator="['fxy08', validatorRules.fxy08]" placeholder="请输入身份证正面"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="8">
              <a-form-item label="身份证反面" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-input v-decorator="['fxy09', validatorRules.fxy09]" placeholder="请输入身份证反面"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="8">
              <a-form-item label="实名状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-input v-decorator="['fxy10', validatorRules.fxy10]" placeholder="请输入实名状态"></a-input>
              </a-form-item>
            </a-col>
          </a-row>
          <!-- </a-collapse-panel> -->
          <!-- </a-collapse> -->
        </div>

        <!-- <a-form-item label="备注1" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'fxy11', validatorRules.fxy11]" placeholder="请输入备注1"></a-input>
        </a-form-item>
        <a-form-item label="备用2" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'fxy12', validatorRules.fxy12]" placeholder="请输入备用2"></a-input>
        </a-form-item>
        <a-form-item label="备用3" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'fxy13', validatorRules.fxy13]" placeholder="请输入备用3"></a-input>
        </a-form-item> -->
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
import { httpAction } from '@/api/manage'
import pick from 'lodash.pick'

export default {
  name: 'FxyConcact01Modal',
  components: {},
  props: {
    mainId: {
      type: String,
      required: false,
      default: ''
    }
  },
  data() {
    return {
      form: this.$form.createForm(this),
      title: '操作',
      width: 1400,
      visible: false,
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },

      confirmLoading: false,
      validatorRules: {
        fxy01: {},
        fxy02: {},
        fxy03: {},
        fxy04: {},
        fxy05: {},
        fxy06: {},
        fxy07: {},
        fxy08: {},
        fxy09: {},
        fxy10: {},
        fxy11: {},
        fxy12: {},
        fxy13: {}
      },
      url: {
        add: '/gzgl01/fxyConcact/addFxyConcact01',
        edit: '/gzgl01/fxyConcact/editFxyConcact01'
      }
    }
  },
  created() {},
  methods: {
    add() {
      this.edit({})
    },
    edit(record) {
      this.form.resetFields()
      this.model = Object.assign({}, record)
      this.visible = true
      this.$nextTick(() => {
        this.form.setFieldsValue(
          pick(
            this.model,
            'createBy',
            'createTime',
            'updateBy',
            'updateTime',
            'sysOrgCode',
            'fxy01',
            'fxy02',
            'fxy03',
            'fxy04',
            'fxy05',
            'fxy06',
            'fxy07',
            'fxy08',
            'fxy09',
            'fxy10',
            'fxy11',
            'fxy12',
            'fxy13'
          )
        )
      })
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      const that = this
      // 触发表单验证
      this.form.validateFields((err, values) => {
        if (!err) {
          that.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!this.model.id) {
            httpurl += this.url.add
            method = 'post'
          } else {
            httpurl += this.url.edit
            method = 'put'
          }
          let formData = Object.assign(this.model, values)
          formData['fxy01'] = this.mainId
          console.log('表单提交数据', formData)
          httpAction(httpurl, formData, method)
            .then(res => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
              that.close()
            })
        }
      })
    },
    handleCancel() {
      this.close()
    },
    popupCallback(row) {
      this.form.setFieldsValue(
        pick(
          row,
          'createBy',
          'createTime',
          'updateBy',
          'updateTime',
          'sysOrgCode',
          'fxy01',
          'fxy02',
          'fxy03',
          'fxy04',
          'fxy05',
          'fxy06',
          'fxy07',
          'fxy08',
          'fxy09',
          'fxy10',
          'fxy11',
          'fxy12',
          'fxy13'
        )
      )
    }
  }
}
</script>
